<template>
  <div class="teacher-layout">
    <el-container>
      <el-header>
        <div class="header-content">
          <h2>教师签到系统</h2>
          <div class="user-info">
            <el-dropdown @command="handleCommand">
              <span class="el-dropdown-link">
                {{ userStore.username }}
                <el-icon class="el-icon--right"><arrow-down /></el-icon>
              </span>
              <template #dropdown>
                <el-dropdown-menu>
                  <el-dropdown-item command="logout">退出登录</el-dropdown-item>
                </el-dropdown-menu>
              </template>
            </el-dropdown>
          </div>
        </div>
      </el-header>
      <el-container>
        <el-aside width="200px">
          <el-menu
            :router="true"
            :default-active="$route.path"
            class="el-menu-vertical"
            background-color="#545c64"
            text-color="#fff"
            active-text-color="#ffd04b">
            <el-menu-item index="/teacher/activities">
              <el-icon><Calendar /></el-icon>
              <span>签到活动</span>
            </el-menu-item>
            <el-menu-item index="/teacher/statistics">
              <el-icon><PieChart /></el-icon>
              <span>签到统计</span>
            </el-menu-item>
          </el-menu>
        </el-aside>
        <el-main>
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
export default {
  name: 'TeacherLayoutPage'
}
</script>

<script setup>
import { useRouter } from 'vue-router'
import { useUserStore } from '@/store/user'
import { ArrowDown, Calendar, PieChart } from '@element-plus/icons-vue'
import { ElMessage } from 'element-plus'

const router = useRouter()
const userStore = useUserStore()

const handleCommand = (command) => {
  if (command === 'logout') {
    userStore.clearUserInfo()
    ElMessage.success('退出成功')
    router.push('/login')
  }
}
</script>

<style scoped>
.teacher-layout {
  min-height: 100vh;
}

.el-header {
  background-color: #409EFF;
  color: white;
  line-height: 60px;
  padding: 0;
}

.header-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 20px;
}

.user-info {
  display: flex;
  align-items: center;
}

.el-dropdown-link {
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
}

.el-aside {
  background-color: #545c64;
  height: calc(100vh - 60px);
}

.el-menu {
  border-right: none;
}

.el-menu-vertical {
  height: 100%;
}

.el-main {
  padding: 20px;
  background-color: #f5f7fa;
}
</style> 